package simple;

import com.rabbitmq.client.*;
import config.RabbitConfig;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author tuyou_cd
 * @date 2020/12/10 17:03
 */
public class RabbitConsumer {
    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitConfig.createChannel();

        channel.basicQos(64);
        Consumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("receive msg:" + new String(body));
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        };

        //消费消息是订阅在队列上面
        channel.basicConsume("queue_demo", consumer);
    }
}
